<?php
class walletController extends RPHP_Controller
{

    //我的钱包
    public function index()
    {

        $m = $this->model;

        $user = $m->checkAuth();
        if ($user) {
            $member_data = $m->getMemberInfo();

            if ($member_data['member_level'] >= 1 && $member_data['level_past_time'] > $_SERVER['REQUEST_TIME']) {

                $member_level = true;
            } else {
                $member_level = false;

            }
            $this->view->member       = $member_data;
            $this->view->member_level = $member_level;
            $this->view->balance      = $m->getBalance();
            $this->display();
        }
    }

    //提现表单
    public function withdraw()
    {

        $m    = $this->model;
        $user = $m->checkAuth();
        if ($user) {

            $this->view->balance = $m->getBalance();
            $this->display();

        }
    }

    //提现表单
    public function pickup()
    {

        $m    = $this->model;
        $user = $m->checkAuth();
        if ($user) {
            $this->view->getSetting = $m->getSetting();

            // print_r($this->view->getSetting);

            $this->view->bank       = $m->myBankList();
            $this->view->balance    = $m->getBalance();
            $this->view->page_title = "提现";
            $this->display();

        }
    }

    public function ajax_pickup()
    {
        $m    = $this->model;
        $user = $m->checkAuth(false);
        if ($user) {
            $res['code'] = 800;
            if ($user['uid'] > 0) {

                $res = $m->doWithdraw($_POST);

            }

            echo exit(json_encode($res));
        }
    }

    //提现记录
    public function detail()
    {
        $m    = $this->model;
        $user = $m->checkAuth();
        if ($user) {

            //提款类型设置 1 全部 2 进行中
            if (isset($_GET['type'])) {
                if (intval($_GET['type']) > 0) {
                    $para['type'] = intval($_GET['type']);
                }

            }

            if (!empty($_GET['startDate'])) {
                $para['startDate'] = addslashes(stripcslashes(trim($_GET['startDate'])));
            }

            if (!empty($_GET['endDate'])) {
                $para['endDate'] = addslashes(stripcslashes(trim($_GET['endDate'])));
            }

            $data = $m->getWithdrawList($para, $page);
            //获取页码
            /* if ($data['maxpage'] > 1) {
            $data['spage'] = $m->fun->spage($data['page'], $data['maxpage']);
            } */
            if ($_GET['act'] == "ajax") {

                echo json_encode($data);

            } else {
                $this->view->data = $data;
                $this->display();
            }

        }

    }

    //收支明细
    public function log()
    {
        $m = $this->model;

        $user = $m->checkAuth();
        if ($user) {
            if (!$_GET['page']) {
                $page = 1;
            } else {
                $page = intval($_GET['page']);
                if ($page < 1) {
                    $page = 1;
                }

            }

            $this->view->data = $m->getFinanceDetail($page);


            $this->display();
        }

    }

    //待入账
    public function drz()
    {
        $m = $this->model;

        $user = $m->checkAuth();
        if ($user) {
            if (!$_GET['page']) {
                $page = 1;
            } else {
                $page = intval($_GET['page']);
                if ($page < 1) {
                    $page = 1;
                }

            }
            $this->view->data = $m->getDRZ($page);
            $this->display();
        }

    }

    //佣金订单
    public function commissionlist()
    {

        $m    = $this->model;
        $user = $m->checkAuth();

        if ($user) {
            $member_data = $m->getUserDetail();
            if ($member_data['member_level'] == 1 && $member_data['level_past_time'] > $_SERVER['REQUEST_TIME']) {

                if (intval($_GET['page']) > 0) {
                    $page = intval($_GET['page']);
                } else {
                    $page = 1;
                }
                $data = $m->getCommissionOrder($page);
                if ($_GET['act'] == "ajax") {

                    echo json_encode($data);
                } else {

                    $this->view->data = $data;
                    $this->display();
                }

            }

        }

    }

    public function ajax()
    {
        $m    = $this->model;
        $user = $m->checkAuth(false);
        if ($user) {

            if ($_POST['act'] == "dowithdraw") {
                $data = $m->doWithdraw($_POST);
            } elseif ($_POST['act'] == "add_bank") {
                unset($_POST['act']);
                $_POST['create_time'] = time();
                $_POST['uid']         = $user['uid'];
                $data['code']         = $m->addData("member_bank_card", $_POST);

            } elseif ($_POST['act'] == "edit_bank") {
                unset($_POST['act']);
                $_POST['uid'] = $user['uid'];
                $data['code'] = $m->edit_bank("member_bank_card", $_POST);

            } elseif ($_POST['act'] == 'get_bank_info') {
                $data = $m->getBankInfo($_POST['bid']);
            } elseif ($_POST['act'] == "add_name") {
                $data = $m->getName($_POST);
            } elseif ($_POST['act'] == "payment") {
                $data = $m->getPaymen($_POST);
            } elseif ($_POST['act'] == "sub_transfer") {

                $data = $m->subTransfer($_POST);
            }elseif ($_POST['act'] == "getlog") {

                $data = $m->getFinanceDetail(intval($_POST['page']));
            }elseif ($_POST['act'] == "getdrz") {

                $data =  $m->getDRZ(intval($_POST['page']));
            }

            echo json_encode($data);
        }

    }

    //我的银行卡
    public function my_bank()
    {

        $m = $this->model;

        $user = $m->checkAuth();
        if ($user) {
            $this->view->data       = $m->myBankList();
            $this->view->page_title = "我的银行卡";
            $this->display();
        }
    }

    //添加银行卡
    public function add_bank()
    {

        $m = $this->model;

        $user = $m->checkAuth();
        if ($user) {
            $type                   = empty($_GET['type']) ? 0 : $_GET['type'];
            $this->view->type       = $type;
            $this->view->page_title = "添加银行卡";
            $this->display();
        }

    }

    //编辑银行卡
    public function edit_bank()
    {
        $m    = $this->model;
        $user = $m->checkAuth();
        if ($user) {
            $this->view->page_title = "编辑银行卡";
            $id                     = addslashes(stripcslashes(trim($_GET['id'])));
            $bank_info              = $m->getBankInfo($id);
            $this->view->info       = $bank_info['info'];
            $this->display();
        }

    }

    //删除银行卡
    public function del_bank()
    {
        $m    = $this->model;
        $user = $m->checkAuth();
        if ($user) {
            $data['code'] = $m->del_bank("member_bank_card", $_POST);
            echo json_encode($data);
        }
    }

/*硒豆转金花*/

    public function transfer_money()
    {
        $m = $this->model;

        $user = $m->checkAuth();
        if ($user) {

            $this->view->setting = $m->getSetting();
            // print_r($this->view->setting);
            $this->view->balance = $m->getBalance();
            $this->display();
        }
    }

}
